/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.javahispano.nettools.cliente.Grafico;

import java.awt.Component;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 *
 * @author Usuario
 */
/*class CustomIconRenderer extends DefaultTreeCellRenderer
{
    ImageIcon defaultIcon;
    ImageIcon specialIcon;

public CustomIconRenderer() {

    defaultIcon = new ImageIcon(CustomIconRenderer.class.getResource("/images/adobe.png"));
    specialIcon = new ImageIcon(CustomIconRenderer.class.getResource("/images/word2.png"));
}

    @Override
public Component getTreeCellRendererComponent(JTree treeObject value,
    boolean sel,boolean expanded,boolean leaf,int row,boolean hasFocus) {

    super.getTreeCellRendererComponent(tree, value, sel,           expanded, leaf, row, hasFocus);
    Object nodeObj = ((DefaultMutableTreeNode)value).getUserObject();
    // check whatever you need to on the node user object
    if (((WhateverNodeObjectClass)nodeObj).someProperty) {
        setIcon(specialIcon);
    } else {
        setIcon(defaultIcon);        }
     }
return this;    }}
 */class CustomIconRenderer extends DefaultTreeCellRenderer {
    ImageIcon defaultIcon;
    ImageIcon specialIcon;
    ImageIcon iconoword;
    ImageIcon iconoexcel;
    ImageIcon iconopowerpoint;
    ImageIcon iconoadobe;
    ImageIcon iconomusica;
    ImageIcon iconoavi;
    ImageIcon iconozip;
    ImageIcon iconosource;
    ImageIcon iconoimagen;
    ImageIcon iconoexe;
    ImageIcon iconoc;
    ImageIcon iconocmas;
    ImageIcon iconophp;

    private final int TYPE_UNKNOWN  = 0;
    private final int TYPE_AUDIO    = 1;
    private final int TYPE_DOCUMENT = 2;
    private final int TYPE_IMAGE    = 3;
    private final int TYPE_SOURCE   = 4;
    private final int TYPE_ZIP      = 5;
    private final int TYPE_VIDEO    = 6;
    private final int TYPE_EXCEL    = 7;
    private final int TYPE_ADOBE    = 8;
    private final int TYPE_EXE      = 9;
    private final int TYPE_POWERPOINT=10;
    private final int TYPE_C=11;
    private final int TYPE_CMAS=12;
    private final int TYPE_PHP=13;
    
    public CustomIconRenderer() {
   //cargamos imagenes
        iconoadobe = new ImageIcon(net.javahispano.nettools.cliente.Grafico.CustomIconRenderer.class.getResource("iconos/adobe.png"));
        iconoword = new ImageIcon(net.javahispano.nettools.cliente.Grafico.CustomIconRenderer.class.getResource("iconos/word2.png"));
        iconoexcel= new ImageIcon(net.javahispano.nettools.cliente.Grafico.CustomIconRenderer.class.getResource("iconos/excel.png"));
        iconopowerpoint = new ImageIcon(net.javahispano.nettools.cliente.Grafico.CustomIconRenderer.class.getResource("iconos/powerpoint.png"));
        iconoadobe = new ImageIcon(net.javahispano.nettools.cliente.Grafico.CustomIconRenderer.class.getResource("iconos/adobe.png"));

       iconomusica = new ImageIcon(net.javahispano.nettools.cliente.Grafico.CustomIconRenderer.class.getResource("iconos/musica.png"));
       iconoavi = new ImageIcon(net.javahispano.nettools.cliente.Grafico.CustomIconRenderer.class.getResource("iconos/avi.png"));
       iconozip = new ImageIcon(net.javahispano.nettools.cliente.Grafico.CustomIconRenderer.class.getResource("iconos/zip.png"));
       iconosource = new ImageIcon(net.javahispano.nettools.cliente.Grafico.CustomIconRenderer.class.getResource("iconos/source.png"));
       iconoimagen = new ImageIcon(net.javahispano.nettools.cliente.Grafico.CustomIconRenderer.class.getResource("iconos/imagenes.png"));
       iconoexe= new ImageIcon(net.javahispano.nettools.cliente.Grafico.CustomIconRenderer.class.getResource("iconos/exe.png"));
       iconoc=new ImageIcon(net.javahispano.nettools.cliente.Grafico.CustomIconRenderer.class.getResource("iconos/c.png"));
       iconocmas=new ImageIcon(net.javahispano.nettools.cliente.Grafico.CustomIconRenderer.class.getResource("iconos/c++.png"));
       iconophp=new ImageIcon(net.javahispano.nettools.cliente.Grafico.CustomIconRenderer.class.getResource("iconos/php.png"));
       //  specialIcon = new ImageIcon(CustomIconRenderer.class.getResource("/iconos/word2.png"));
    }

    @Override
    public Component getTreeCellRendererComponent(JTree tree,
      Object value,boolean sel,boolean expanded,boolean leaf,
      int row,boolean hasFocus) {

        super.getTreeCellRendererComponent(tree, value, sel,
          expanded, leaf, row, hasFocus);
      String ext;
      String aux;
      int tipo;
        Object nodeObj = ((DefaultMutableTreeNode)value).getUserObject();
        System.out.println("Este es el nodoxxxxxxxxxxxxxx"+nodeObj.toString());
        aux=nodeObj.toString();
        File f = new File (aux);

        tipo=extensionType(f);
        System.out.println("++++++++++++++++++++tipo======"+tipo);
        if(tipo==1)//audio
            setIcon(iconomusica);
        if (tipo==2)//Doumento de texto
            setIcon(iconoword);
        if (tipo==3)//imagen
            setIcon(iconoimagen);
        if (tipo==4)//codigo
            setIcon(iconosource);
        if (tipo==5)//Elemento comprimido
            setIcon(iconozip);
        if (tipo==6)//peliculas
            setIcon(iconoavi);
        if (tipo==7)//excel
             setIcon(iconoexcel);
        if (tipo==8)//adobe
             setIcon(iconoadobe);
        if (tipo==9)//ejecutable y instalables
             setIcon(iconoexe);
        if(tipo==10)//powerpoint
            setIcon(iconopowerpoint);
        if(tipo==11)//c
            setIcon(iconoc);
        if(tipo==12)
            setIcon(iconocmas);
        if(tipo==13)
             setIcon(iconophp);
        // else
         //   setIcon(defaultIcon);
        //} catch (Exception e) {
       // }

        return this;
    }


     public int extensionType(File f) {
        String name = f.getName();
        String ext = "";
        try {
            ext = name.substring(name.lastIndexOf('.') + 1, name.length());
        } catch (Exception e) {
        }
  /** Audio */
         System.out.println("EXT"+ext);
        if (ext.equalsIgnoreCase("mp3"))
            return TYPE_AUDIO;
        if (ext.equalsIgnoreCase("wav"))
            return TYPE_AUDIO;
        if (ext.equalsIgnoreCase("au"))
            return TYPE_AUDIO;
        if (ext.equalsIgnoreCase("wma"))
            return TYPE_AUDIO;

        /** Documentos */
        if (ext.equalsIgnoreCase("doc"))
            return TYPE_DOCUMENT;
        if (ext.equalsIgnoreCase("rtf"))
            return TYPE_DOCUMENT;
        if (ext.equalsIgnoreCase("odt"))
            return TYPE_DOCUMENT;
        //if (ext.equals("xls"))
         //   return TYPE_DOCUMENT;
        if (ext.equalsIgnoreCase("ods"))
            return TYPE_DOCUMENT;
        if (ext.equalsIgnoreCase("doc"))
            return TYPE_DOCUMENT;
        if (ext.equalsIgnoreCase("txt"))
            return TYPE_DOCUMENT;
        //excel
         if (ext.equalsIgnoreCase("xls"))
             return  TYPE_EXCEL;
         if (ext.equalsIgnoreCase("xlsx"))
             return  TYPE_EXCEL;

         //powerpoint
         if (ext.equalsIgnoreCase("ppt"))
             return  TYPE_POWERPOINT;
         if (ext.equalsIgnoreCase("pps"))
             return  TYPE_POWERPOINT;
         if (ext.equalsIgnoreCase("pptx"))
             return  TYPE_POWERPOINT;
         if (ext.equalsIgnoreCase("ppsx"))
             return  TYPE_POWERPOINT;


         /** Imagenes */
        if (ext.equalsIgnoreCase("jpg"))
            return TYPE_IMAGE;
        if (ext.equalsIgnoreCase("gif"))
            return TYPE_IMAGE;
        if (ext.equalsIgnoreCase("bmp"))
            return TYPE_IMAGE;
        if (ext.equalsIgnoreCase("png"))
            return TYPE_IMAGE;
         if (ext.equalsIgnoreCase("JEPG"))
            return TYPE_IMAGE;

         /** Fuentes */
        if (ext.equalsIgnoreCase("java"))
            return TYPE_SOURCE;
        if (ext.equalsIgnoreCase("class"))
            return TYPE_SOURCE;
        if (ext.equalsIgnoreCase("cpp"))
            return TYPE_CMAS;
        if(ext.equalsIgnoreCase("c"))
            return TYPE_C;
         if(ext.equalsIgnoreCase("def"))
            return TYPE_C;
         if(ext.equalsIgnoreCase("h"))
             return TYPE_C;
          if(ext.equalsIgnoreCase("php"))
             return TYPE_PHP;


        /** Comprimidos */
        if (ext.equalsIgnoreCase("zip"))
            return TYPE_ZIP;
        if (ext.equalsIgnoreCase("rar"))
            return TYPE_ZIP;
        if (ext.equalsIgnoreCase("7z"))
            return TYPE_ZIP;
        if (ext.equalsIgnoreCase("bzip2"))
            return TYPE_ZIP;
        if (ext.equalsIgnoreCase("gzip"))
            return TYPE_ZIP;
         if (ext.equalsIgnoreCase("tar"))
            return TYPE_ZIP;

         /**Video*/
         if (ext.equalsIgnoreCase("avi"))
            return TYPE_VIDEO;
         if (ext.equalsIgnoreCase("3GP"))
            return TYPE_VIDEO;
          if (ext.equalsIgnoreCase("OGM"))
            return TYPE_VIDEO;
         if (ext.equalsIgnoreCase("Ogg"))
            return TYPE_VIDEO;
         if (ext.equalsIgnoreCase("mov"))
            return TYPE_VIDEO;
         if (ext.equalsIgnoreCase("ASF"))
            return TYPE_VIDEO;
         if (ext.equalsIgnoreCase("IFF"))
            return TYPE_VIDEO;
         if (ext.equalsIgnoreCase("MPEG"))
            return TYPE_VIDEO;

         //ejecutables y instalables
         if (ext.equalsIgnoreCase("exe"))
            return TYPE_EXE ;
         if (ext.equalsIgnoreCase("sys"))
            return TYPE_EXE ;
         if (ext.equalsIgnoreCase("DLL"))
            return TYPE_EXE;
        if (ext.equalsIgnoreCase("bat"))
            return TYPE_EXE;
         if (ext.equalsIgnoreCase("dat"))
            return TYPE_EXE;
         if (ext.equalsIgnoreCase("log"))
            return TYPE_EXE;
         if (ext.equalsIgnoreCase("ini"))
            return TYPE_EXE;
         if (ext.equalsIgnoreCase("bin"))
            return TYPE_EXE;
         if (ext.equalsIgnoreCase("inf"))
            return TYPE_EXE;
         //adobe
         if (ext.equalsIgnoreCase("pdf"))
            return TYPE_ADOBE;

        else
            return TYPE_UNKNOWN;



     }



}